package office.service.hr.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.action.hr.form.OfficesuppliesForm;
import office.action.hr.wrapper.OfficesuppliesWrapper;
import office.bo.hr.IOfficesupplies;
import office.bo.hr.impl.Officesupplies;
import office.domainset.BizDomainProviderSetImpl;
import office.service.hr.IOfficesuppliesService;
import platform.common.exception.BusinessException;
import platform.common.service.impl.BaseBizServiceImpl;
import platform.util.Util;

public class OfficesuppliesServiceImpl extends BaseBizServiceImpl implements IOfficesuppliesService{

	/**
	 * 获取申请办公用品信息
	 * @return
	 * @throws BusinessException
	 */
	public List getOfficesuppliesList() throws BusinessException{
		List listData = new ArrayList() ;
		OfficesuppliesWrapper wrapper ; 
		try {
			Map mapSort = Util.parsePropertiesReturnMap("office","OfficesuppliesSort.size");
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			List list = domainProviderSetImpl.getDao().findAllByDomian(domainProviderSetImpl.getOfficesuppliesDP());
			for (int i = 0; i < list.size(); i++) {
				Officesupplies bo = (Officesupplies)list.get(i);
				wrapper = new OfficesuppliesWrapper();
				wrapper.copyToWrapper(bo, mapSort);
				listData.add(wrapper);
			}
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("获取办公用品信息失败!", e);
		}
		return listData;
	}
	/**
	 * 编辑申请办公用品
	 * @throws BusinessException
	 */
	public void editOfficesupplies(OfficesuppliesForm objctForm)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			Officesupplies bo = (Officesupplies)domainProviderSetImpl.getOfficesuppliesDP().newEmptyObj();
			bo =(Officesupplies) objctForm.copyPropertiesToBO(bo);
			if(null==bo.getId() || ("").equals(bo.getId())){
				bo.generatorUUID();
			}
			//验证是否存在重复记录
			bo.store(domainProviderSet);
			
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("编辑办公用品信息失败!", e);
		}
	}
	/**
	 * 根据id获取对象
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	public OfficesuppliesForm getById(String id)throws BusinessException{
		OfficesuppliesForm form = new OfficesuppliesForm();
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IOfficesupplies bo = (IOfficesupplies)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getOfficesuppliesDP(), id);
			Map map = new HashMap();
			form.copyPropertiesFromBO(bo,map);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id获取办公用品信息对象失败!", e);
		}
		return form;
	}
	/**
	 * 根据id删除对象
	 * @param id
	 * @throws BusinessException
	 */
	public void deleteById(String id)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().deleteById(domainProviderSetImpl.getOfficesuppliesDP(), id);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id删除办公用品信息对象失败!", e);
		}
	}
}
